/**
 * 
 */
package com.appspot.mobileirisnextbus.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;

import com.appspot.mobileirisnextbus.server.SimpleBusServiceImpl;

/**
 * @author adjunaedi
 * 
 */
public class BusServlet extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private SimpleBusServiceImpl simpleBusServiceImpl = new SimpleBusServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
        String xslPath = this.getServletContext().getRealPath("/WEB-INF/bus.xsl");
        String busNum = req.getParameter("bus");

        String rawData = this.simpleBusServiceImpl.getRawData(busNum);
        String finalMarkup = "";
        try {
            finalMarkup = this.simpleBusServiceImpl.generateFinalMarkup(rawData, xslPath);
        } catch (TransformerConfigurationException e) {
            e.printStackTrace();
        } catch (TransformerFactoryConfigurationError e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }

        resp.getWriter().write(finalMarkup);
    }
}
